package com.hqbzl.chat.service.impl;

import com.google.common.collect.ImmutableMap;
import com.hqbzl.chat.annotations.RpcClientService;
import com.hqbzl.chat.annotations.RpcServerService;
import com.hqbzl.chat.model.UserInfo;
import com.hqbzl.chat.service.UserService;

import java.util.UUID;

@RpcServerService
public class UserServiceImpl implements UserService {

    final ImmutableMap<String, String> build = ImmutableMap.<String, String>builder()
            .put("admin", "123")
            .put("ctx", "001")
            .put("aa", "a01")
            .put("bb", "b01")
            .put("cc", "c01")
            .put("dd", "d01")
            .put("ee", "e01")
            .build();

    @Override
    public boolean login(String userName, String password) {
        final String up = build.get(userName);
        return up != null && up.equals(password);
    }

    @Override
    public String say(String a, String b) {
        int r = 1 / 0;
        System.out.println("say: " + a + " " + b);
        return String.format("hello %s %s,%s", UUID.randomUUID().toString(), a, b);
    }

    @Override
    public UserInfo info(String name) {
        return UserInfo.builder().name(name).addr(UUID.randomUUID().toString()).build();
    }
}
